# All rights reserved.
#
# This is free software, licensed under the GNU General Public License v2.
# See /LICENSE for more information.

include $(TOPDIR)/rules.mk
include $(INCLUDE_DIR)/kernel.mk

PKG_NAME:=mt7603e
P4REV:=
PKG_VERSION:=4.0.1.0
PKG_SOURCE:=MT7603e_LinuxAP_V4.0.1.0rev1_DPA_20150629.tar.bz2
PKG_SOURCE_URL:=http://localhost/
PKG_BUILD_DIR:=$(KERNEL_BUILD_DIR)/$(PKG_NAME)-$(PKG_VERSION)
PKG_KCONFIG:= \
	RALINK_MT7620 RALINK_RT7621 RLT_WIFI MT_WIFI_PATH\
	FIRST_IF_EEPROM_PROM FIRST_IF_EEPROM_EFUSE FIRST_IF_EEPROM_FLASH RT_FIRST_CARD_EEPROM WIFI_BASIC_FUNC\
	MULTI_INF_SUPPORT WSC_INCLUDED WSC_V2_SUPPORT DOT11N_DRAFT3 DOT11_VHT_AC DOT11W_PMF_SUPPORT\
	TXBF_SUPPORT WMM_ACM_SUPPORT  QOS_DLS_SUPPORT WAPI_SUPPORT CARRIER_DETECTION_SUPPORT\
	IGMP_SNOOP_SUPPORT BLOCK_NET_IF RATE_ADAPTION NEW_RATE_ADAPT_SUPPORT AGS_SUPPORT\
	IDS_SUPPORT WIFI_WORK_QUEUE WIFI_SKB_RECYCLE RTMP_FLASH_SUPPORT LED_CONTROL_SUPPORT\
	SINGLE_SKU_V2 HW_ANTENNA_DIVERSITY ATE_SUPPORT RT2860V2_AP_V24_DATA_STRUCTURE RT2860V2_AP_32B_DESC\
	MEMORY_OPTIMIZATION HOTSPOT HOTSPOT_R2 ACL_V2_SUPPORT UAPSD PA_LNA RLT_BBP RLT_RF RTMP_BBP RTMP_RF RLT_MAC RLT_BBP RLT_RF RTMP_MAC RTMP_BBP RTMP_RF \
	RTMP_PCI_SUPPORT RTMP_USB_SUPPORT RTMP_RBUS_SUPPORT RLT_AP_SUPPORT RALINK_MT7603E MT_MAC AP_SUPPORT\
	WDS_SUPPORT MBSS_SUPPORT NEW_MBSSID_MODE ENHANCE_NEW_MBSSID_MODE APCLI_SUPPORT MULTI_APCLI_SUPPORT \
	AIRPLAY_SUPPORT MAC_REPEATER_SUPPORT DFS_SUPPORT NINTENDO_AP DOT11K_RRM_SUPPORT RT2860V2_SNMP\
	LLTD_SUPPORT NINTENDO_AP COC_SUPPORT MULTI_CORE_SUPPORT MCAST_RATE_SPECIFIC PREVENT_ARP_SPOOFING_SUPPORT \
	EXT_BUILD_CHANNEL_LIST  AUTO_CH_SELECT_ENHANCE MEMORY_OPTIMIZATION RTMP_TEMPERATURE_CALIBRATION\
	SNIFFER_SUPPORT CFG80211_SUPPORT SNIFFER_MIB_CMD ALL_NET_EVENT 
	

PKG_CONFIG_DEPENDS:=$(foreach c, $(PKG_KCONFIG),$(if $(CONFIG_$c),CONFIG_$(c)))

include $(INCLUDE_DIR)/package.mk

TAR_CMD=$(HOST_TAR) -C $(1)/ $(TAR_OPTIONS)

define KernelPackage/mt7603e
  CATEGORY:=MTK Properties
  TITLE:=MTK MT7603e wifi AP driver
  FILES:=$(PKG_BUILD_DIR)/rlt_wifi_ap/mt7603e.ko
  SUBMENU:=Drivers
  MENU:=1
endef

define KernelPackage/mt7603e/config
	source "$(SOURCE)/config.in"
endef

define P4/Info
  P4URL:=//Embedded_WIFI/MP/MT7603/rlt_wifi/
endef

define P4/Release
  make RT28xx_MODE=AP CHIPSET=mt7603e build_tools
  make WIFI_MODE=AP CHIPSET=mt7603e RELEASE=DPA release 2>&1
  mv DPA src
  cp -rf rlt_wifi_ap build
  #cp build/Makefile.mt_wifi_ap build/Makefile
  #cp build/Kconfig.mt_wifi_ap build/Kconfig
  tar cjf mt7603e.tar.bz2 build src
endef

define Build/Compile
	$(MAKE) -C "$(LINUX_DIR)" V=1 \
		CROSS_COMPILE="$(TARGET_CROSS)" \
		ARCH="$(LINUX_KARCH)" \
		SUBDIRS="$(PKG_BUILD_DIR)/rlt_wifi_ap" \
		$(foreach c, $(PKG_KCONFIG),$(if $(CONFIG_MT7603E_$c),CONFIG_$(c)=$(CONFIG_MT7603E_$(c)))) \
		modules
endef

define KernelPackage/mt7603e/install
	$(INSTALL_DIR) $(1)/lib/wifi/
	$(INSTALL_BIN) ./files/mt7603e.sh $(1)/lib/wifi/
#	$(INSTALL_BIN) ./files/ralink_common.sh $(1)/lib/wifi/
	$(INSTALL_DIR) $(1)/etc/wireless/mt7603e/
#	$(INSTALL_BIN) ./files/mt7603e.dat $(1)/etc/wireless/mt7603e/
	-$(INSTALL_BIN) ./files/mt7603e.eeprom.bin $(1)/etc/wireless/mt7603e/
	echo p$(P4REV) > $(1)/etc/wireless/mt7603e/version
endef

$(eval $(call KernelPackage,mt7603e))
